// <copyright file="EasyWebApp.cs" company="<Customer Name>">This is a "work-for-hire". or Copyright (C) 2010 MicroCODE Incorporated Troy, MI</copyright><author><Class Author's Name></author>

/*
 *      Title:    <Class Description>
 *      Module:   ClassTemplate (<Namespace>:ClassTemplate.cs)
 *      Project:  <Project Name>
 *      Customer: <Customer Name>
 *      Facility: MicroCODE Incorporated
 *      Date:     <Class Creation Date>
 *      Author:   <Class Author's Name>
 * 
 * 
 * 
 *  
 *      MODIFICATIONS:
 *      --------------
 *
 *  Date:         By-Group:   Rev:     Description:
 *
 *  DD-Mmm-YYYY   XYZ-GROUP  {0001}    Describe reason for creating or modifying class... 
 * 
 * 
 * 
 */
using System;
using System.Data;
using Org.EasyWeb.SysUtil;

namespace Org.EasyWeb.Sys
{
    public class InitializeErrorObject
    {
        // Fields
        private static InitializeErrorObject ErrorObject = new InitializeErrorObject();
        private DataTable fDupTable = DataSetUtil.CreateDataTable("DUPLICATE", new string[] { "RegCategory", "Name", "Type", "File" });
        private DataTable fInvalidDll = DataSetUtil.CreateDataTable("INVALID_DLL", new string[] { "File", "ErrorMsg" });
        private DataTable fInvalidType = DataSetUtil.CreateDataTable("INVALID_TYPE", new string[] { "File", "ErrorMsg" });

        // Methods
        private InitializeErrorObject()
        {
        }

        private void AddDataSet(DataSet dataSet)
        {
            if (!(this.IsNoError || !AppSettings.Current.Debug))
            {
                dataSet.Tables.Add(this.fDupTable);
                dataSet.Tables.Add(this.fInvalidDll);
                dataSet.Tables.Add(this.fInvalidType);
            }
        }

        public static void AddDuplicate(string regCategory, string name, Type type, string file)
        {
            if (AppSettings.Current.Debug)
            {
                ErrorObject.AddDuplicateInfo(regCategory, name, type, file);
            }
        }

        private void AddDuplicateInfo(string regCategory, string name, Type type, string file)
        {
            DataRow row = this.fDupTable.NewRow();
            DataSetUtil.SetRowValues(row, new object[] { regCategory, name, (type == null) ? string.Empty : type.ToString(), file });
            this.fDupTable.Rows.Add(row);
        }

        public static void AddErrorObjects(DataSet dataSet)
        {
            ErrorObject.AddDataSet(dataSet);
        }

        public static void AddInvalidDll(string file, System.Exception ex)
        {
            if (AppSettings.Current.Debug)
            {
                ErrorObject.AddInvalidDllInfo(file, ex);
            }
        }

        private void AddInvalidDllInfo(string file, System.Exception ex)
        {
            DataRow row = this.fInvalidDll.NewRow();
            DataSetUtil.SetRowValues(row, new object[] { file, ex.Message });
            this.fInvalidDll.Rows.Add(row);
        }

        public static void AddInvalidType(string file, System.Exception ex)
        {
            if (AppSettings.Current.Debug)
            {
                ErrorObject.AddInvalidTypeInfo(file, ex);
            }
        }

        private void AddInvalidTypeInfo(string file, System.Exception ex)
        {
            DataRow row = this.fInvalidType.NewRow();
            DataSetUtil.SetRowValues(row, new object[] { file, ex.Message });
            this.fInvalidType.Rows.Add(row);
        }

        // Properties
        public static bool IsError
        {
            get
            {
                return !ErrorObject.IsNoError;
            }
        }

        private bool IsNoError
        {
            get
            {
                return (((this.fDupTable.Rows.Count == 0) && (this.fInvalidDll.Rows.Count == 0)) && (this.fInvalidType.Rows.Count == 0));
            }
        }
    }
}